package com.inwavetech.os.sync.jsonparser;

import com.inwavetech.os.entity.Product;
import com.inwavetech.os.entity.enummap.ProductDiagnosysMap;
import com.inwavetech.os.util.SyncDateFormat;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * Created by jgskin on 2/28/14.
 */
public class ProductJsonParser extends BaseJsonParser {

    public ProductJsonParser(ProductDiagnosysMap diagnosysMap, SyncDateFormat syncDateFormat) {
        super();

        expectedKeys.add("name");
        expectedKeys.add("identification");
        expectedKeys.add("factory_warranty");
        expectedKeys.add("service_warranty");
        expectedKeys.add("document_code");
        expectedKeys.add("maintenance_type");
        expectedKeys.add("hired_services");
        expectedKeys.add("maintenance_detail");
        expectedKeys.add("setup_detail");
        expectedKeys.add("diagnostic_detail");
        expectedKeys.add("diagnostic_id");
        expectedKeys.add("document_date");

        cleaners.put("diagnostic_id", new EnumCleaner(diagnosysMap, false));

        cleaners.put("document_date", new DateCleaner(syncDateFormat, false));
    }

    @Override
    protected void populate(HashMap<String, Object> cleanedValues, Object object) {
        Product product = (Product) object;
        
        product.diagnosys = (Product.Diagnosys) cleanedValues.get("diagnostic_id");
        product.document_date = (Date) cleanedValues.get("document_date");

        product.original_id = (String) cleanedValues.get("id");
        product.name = (String) cleanedValues.get("name");
        product.identification = (String) cleanedValues.get("identification");
        product.factory_warranty = (String) cleanedValues.get("factory_warranty");
        product.service_warranty = (String) cleanedValues.get("service_warranty");
        product.document_code = (String) cleanedValues.get("document_code");
        product.maintenance_type = (String) cleanedValues.get("maintenance_type");
        product.hired_services = (String) cleanedValues.get("hired_services");
        product.maintenance_detail = (String) cleanedValues.get("maintenance_detail");
        product.setup_detail = (String) cleanedValues.get("setup_detail");
        product.diagnosys_detail = (String) cleanedValues.get("diagnostic_detail");
    }
}
